package com.feizi.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.feizi.entity.OrderdetailEntity;
import com.feizi.entity.OrderinfoEntity;
import com.feizi.entity.OrderinfoSelectEntity;
import com.feizi.entity.ShipmentsEntity;
import com.feizi.service.OrderService;
@Controller
public class OrderController {
	
	@Autowired
	private OrderService orderService;
	/**
	 * 查询
	 * @param ose
	 * @return
	 */
	@RequestMapping(path="/findOrder.do",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> find(OrderinfoSelectEntity ose) {
		Map<String, Object> relMap=new HashMap<String, Object>();
		ose.setOffset((ose.getPage() - 1) * ose.getLimit());
		List<OrderinfoEntity> list=orderService.find(ose);
		int count=orderService.getCount(ose);
		relMap.put("code", "0");
		relMap.put("msg", "success");
		relMap.put("count", count);
		relMap.put("data", list);
		return relMap;
	}
	/**
	 * 订单详情表
	 * @param orderid
	 * @return
	 */
	@RequestMapping(path="/findOrderdetail.do",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> findOrderdetail(String orderid){
		Map<String, Object> relMap=new HashMap<String, Object>();
		List<OrderdetailEntity> list=orderService.finddetail(orderid);
		relMap.put("code", "1");
		relMap.put("msg", "success");
		relMap.put("count", "");
		relMap.put("data", list);
		return relMap;
	}
	/**
	 * 修改地址
	 * @param oie
	 * @return
	 */
	@RequestMapping(path="/upOrder.do",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> upOrder(OrderinfoEntity oie){
		Map<String, Object> relMap=new HashMap<String, Object>();
		int rows=orderService.upOrder(oie);
		relMap.put("code",rows>0? "0":"1");
		relMap.put("msg",rows>0? "修改收货地址成功":"修改收货地址失败");
		return relMap;
	}
	/**
	 * 发货
	 * @param orderid
	 * @return
	 */
	@RequestMapping(path="/shipments.do",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> shipments(ShipmentsEntity se){
		Map<String, Object> relMap=new HashMap<String, Object>();
		int rows=orderService.shipments(se);
		relMap.put("code",rows>0? "0":"1");
		relMap.put("msg",rows>0? "发货成功":"发货失败");
		return relMap;
	}
}
